<template>
<slot :controller="controller" :store="store" :model="model">
    <AppSDViewLayout :class="classNames" :openType="openType">
        <template v-if="!noViewCaption && model.showCaption" #viewHeaderContentLeft>
            <div class="view-header__caption">
                <slot name="ViewCaption" :controller="controller" :store="store" :model="model">
                    <AppCaptionBar :caption="model.caption" :title="model.title" :capPSLanguageRes="model.capPSLanguageRes" :titlePSLanguageRes="model.titlePSLanguageRes" :openType="openType"></AppCaptionBar>
                </slot>
                <slot name="ViewDataInfoBar" :controller="controller" :store="store" :model="model">
                    <AppDataInfoBar v-if="model.showDataInfoBar" :dataInfo="store.dataInfo"></AppDataInfoBar>
                </slot>
            </div>
        </template>
        <template #viewHeaderContentRight>
            <div class="view-header__toolbar">
                <slot name="ViewActions" :controller="controller" :store="store" :model="model" :actions="{ handleToolbarItemClick, handleActionClick, handleDynamicToolbarClick }">
                <slot name="ViewToolbar" :controller="controller" :store="store" :model="model" :actions="{ handleToolbarItemClick }">
                    <AppToolbar
                        name="toolbar"
                        mode="DEFAULT"
                        :items="store.toolbarItems"
                        :loading="store.loadingHelper.isLoading"
                        @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
                    </AppToolbar>
                </slot>
                <slot name="ViewFormAction" :controller="controller" :store="store" :model="model" :actions="{ handleActionClick }">
                <template v-if="store.actionGroup">
                    <template v-for="(item, index) in store.actionGroup.details" :key="index">
                        <AppButton
                            v-show="item.visible"
                            :disabled="item.disabled"
                            :loading="store.loadingHelper.isLoading"
                            @click="(event: MouseEvent) => handleActionClick(event, item)">
                            <AppIconText
                                :iconClass="item.showIcon && item.iconClass"
                                :imgPath="item.showIcon && item.imgPath"
                                :text="item.showCaption && item.caption"
                            />
                        </AppButton>
                    </template>
                </template>
                </slot>
                <slot name="ViewDynaAction" :controller="controller" :store="store" :model="model" :actions="{ handleDynamicToolbarClick }">
                <template v-for="(item, index) in store.dynamicToolbar" :key="index">
                        <AppButton
                            :loading="store.loadingHelper.isLoading"
                            @click="handleDynamicToolbarClick(item)">
                            <AppIconText :text="item.sequenceFlowName" />
                        </AppButton>
                </template>
                </slot>
                </slot>
            </div>
        </template>
        <template #default>
            <slot name="ViewContent" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
            <a-tabs class="view-content__body__wfdynaeditview3tabs">
                <a-tab-pane :key="store.activeForm.codeName" :tab="model.editItemCaption ? model.editItemCaption : store.activeForm.logicName">
                    <component
                        v-if="store.activeForm.codeName"
                        :name="store.activeForm.name"
                        :is="componentList[`${store.activeForm.name}Form`]"
                        :actions="store.activeForm.actions"
                        :context="store.context"
                        :isEditable="store.isEditable"
                        :viewParams="store.viewParams"
                        :closeView="store.closeView"
                        :pLoadingHelper="store.loadingHelper"
                        :openView="store.openView"
                        :newView="store.newView"
                        @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
                        @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
                        @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }" />
                </a-tab-pane>
                <template v-if="model.tabPages">
                    <a-tab-pane v-for="page in model.tabPages" :key="page.viewName">
                        <template #tab>
                            {{$t(page.capPSLanguageRes, page.caption)}}
                        </template>
                        <component
                            openType="EMBED"
                            :is="viewComponentList[page.viewName]"
                            :key="page.viewName"
                            :context="store.context"
                            :viewParams="store.viewParams"
                            :pLoadingHelper="store.loadingHelper"
                            :appDeCodeName="model.entityCodeName"
                            class="view-container2">
                        </component>
                    </a-tab-pane>
                </template>
            </a-tabs>
            </slot>
        </template>
    </AppSDViewLayout>
</slot>
</template>
<script lang="ts" setup>
// 基于template/src/views/{{appModules}}/{{pages@DEWFDYNAEDITVIEW3}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppSDViewLayout } from "@components/layout/sd-view-layout";
import { AppToolbar } from '@components/widgets/toolbar';
import formForm from '@widgets/ibiz-sample-0021/usr-1114284368-form/usr-1114284368-form.vue';
import wfform_operationformForm from '@widgets/ibiz-sample-0021/operation-form-form/operation-form-form.vue';
import { IEvent, IParam, IWFDynaEditView3Ability, IWFDynaEditView3Store, WFDynaEditView3ActionType } from '@/core';
import { useController, useProps, useBasic, useAction} from './ibiz-sample-0021-usr-1114865995-wf-dyna-edit-view-3-hook';
import AppWFStepTraceView from '@views/app-wf-step-trace-view/app-wf-step-trace-view.vue';
// 组件注册
const componentList:any = {
formForm,
wfform_operationformForm,
}
// 组件注册
const viewComponentList: any = {
AppWFStepTraceView,
};



// 输入参数
const props = defineProps(useProps());

// 基础数据
const { 
    model,
    getClassNames, 
    useNavParamsBind,
	useEventBind,
    handleQuickSearch,
    handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy 
} = useBasic(props);



const emit = defineEmits<{
    (event: 'view-action', name: string, action: WFDynaEditView3ActionType, data: IParam[]): void;
    (event: 'view-init', name: string, data: IWFDynaEditView3Ability): void;
    (event: 'view-mounted', name: string, data: IParam): void;
    (event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  	return getClassNames(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IWFDynaEditView3Store = controller.getStore();

onMounted(() => {
    controller.viewMounted();
})

onUnmounted(() => {
    controller.viewDestroy();
})

const { handleActionClick, handleDynamicToolbarClick, handleToolbarItemClick } = useAction(controller);
</script>
